// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.

#include "port/port_win32.h"

#include <cstdlib>
#include <stdio.h>
#include <string.h>
#include "util/logging.h"

namespace leveldb {
namespace port {
	BOOL CALLBACK InitHandleFunction (
		OnceType* InitOnce,        
		PVOID Parameter,            
		PVOID *lpContext){
			((void (*)())Parameter)();
			return TRUE;
	}
void InitOnce(OnceType* once, void (*initializer)()){
	PVOID lpContext;
	BOOL  bStatus;

	// Execute the initialization callback function 
	bStatus = InitOnceExecuteOnce(once,          // One-time initialization structure
		InitHandleFunction,   // Pointer to initialization callback function
		initializer,                 // Optional parameter to callback function (not used)
		&lpContext);          // Receives pointer to event object stored in g_InitOnce
	if(!bStatus){
		throw std::runtime_error("init fail");
	}
}
Mutex::Mutex(){}
 
void Mutex::Lock() { this->m_.acquire(); }

void Mutex::Unlock() { this->m_.release();}

CondVar::CondVar(Mutex* mu)
    : cond_(mu->m_) {
}



void CondVar::Wait() {
	this->cond_.wait();
}

void CondVar::Signal() {
	//this->cond_.signal();  
	this->cond_.broadcast();
}

void CondVar::SignalAll() {
	this->cond_.broadcast();
}

}  // namespace port
}  // namespace leveldb
